var _hbssCount = 'http://localhost:8181/count';

var _debug=true;
var _hbssType;
var _hbssShow;
var _hbssShowStr='';
var _hbssIframe;

var _hbssCountPage = _hbssCount + '/count/count.php';
if( _hbssIframe == true )
{
	var _hbssPageurl = escape(location.href);
	var _hbssReferer = escape(document.referrer);
}
else
{
	var _hbssPageurl = escape(top.location.href);
	var _hbssReferer = escape(top.document.referrer);
}

var _hbssLanguage = (navigator.systemLanguage?navigator.systemLanguage:navigator.language);
var _hbssColor = screen.colorDepth;
var _hbssScreenSize = screen.width + '*' + screen.height;
var _hbssCharset = getPageCharset();


var _hbssFirstTime;
var _hbssLastTime;
_hbssFirstTime = _hbssReadCookie( '_hbssFirstTime' );
if( _hbssFirstTime == '' )
{
	_hbssFirstTime = getTime();
	_hbssLastTime = _hbssFirstTime;
	_hbssWriteCookie( '_hbssFirstTime', _hbssFirstTime, 10000 );
}
else
{
	_hbssLastTime = getTime();
}

if( _hbssType == null )
{
	_hbssType = 1;
}

_hbssReturnCount = _hbssReadCookie( '_hbssReturnCount' );
_hbssReturnCount = _hbssReturnCount == '' ? 0 : _hbssReturnCount;

_hbssReturnTime = _hbssReadCookie( '_hbssReturnTime' );
if( _hbssReturnTime == '' )
{
	_hbssReturnTime = getTime();
	_hbssWriteCookie( '_hbssReturnTime', _hbssReturnTime, 10000 );
}

temp = _hbssReturnTime.split( '-' )
_hbssReturnTimeDate = new Date(temp[0], temp[1]-1, temp[2], temp[3], temp[4], temp[5] );
_hbssNowTimeDate = new Date();

if( _hbssNowTimeDate - _hbssReturnTimeDate >= 43200000 )
{
	_hbssWriteCookie( '_hbssReturnCount', ++_hbssReturnCount, 10000 );
	_hbssWriteCookie( '_hbssReturnTime', getTime(), 10000 );
}
else
{
	_hbssReturnCount = null;
}


if( _hbssShow != null && _hbssShow.length > 0 )
{
	var _hbssShowStr = '';
	for( i = 0; i < _hbssShow.length; i ++ )
	{
		_hbssShowStr += "&show[]=" + _hbssShow[i];
	}
}
else
{
	var _hbssShowStr = "";
}



var _hbssCountUrl = _hbssCountPage + '?'
+ '&counturl=' + _hbssCount
+ '&pageurl=' + _hbssPageurl
+ '&referer=' + _hbssReferer
+ '&language=' + _hbssLanguage
+ '&color=' + _hbssColor
+ '&screensize=' + _hbssScreenSize
+ '&debug=' + _debug
+ '&firsttime=' + _hbssFirstTime
+ '&lasttime=' + _hbssLastTime
+ '&type=' + _hbssType
+ '&charset=' + _hbssCharset
+ _hbssShowStr
+ '&timezone=' + (new Date()).getTimezoneOffset()/60;

if( _hbssReturnCount != null )
{
	_hbssCountUrl += '&return1=' + _hbssReturnCount;
}


if( _debug )
{
	document.write(_hbssCountUrl);
	document.write("<iframe src='" + _hbssCountUrl + "' width=100% height=500></iframe>");
}
else
{
	document.write("<script src='" + _hbssCountUrl + "'></script>");
}



//Functions

function getTime() 
{ 
	now = new Date(); 
	year=now.getYear();
	Month=now.getMonth()+1;
	Day=now.getDate();
	Hour=now.getHours(); 
	Minute=now.getMinutes(); 
	Second=now.getSeconds(); 
	return year+"-"+Month+"-"+Day+"-"+Hour+"-"+Minute+"-"+Second;
} 


function _hbssReadCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function _hbssWriteCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire + "domain=;" + "path=/;";
}

function getPageCharset(){
    var charSet = "";
    var oType = getBrowser();
    switch(oType){
        case "IE":
            charSet = document.charset;
            break;
        case "FIREFOX":
            charSet = document.characterSet;
            break;
        default:
            break;
    }
    return charSet;
}

function getBrowser(){
    var oType = "";
    if(navigator.userAgent.indexOf("MSIE")!=-1){
        oType="IE";
    }else if(navigator.userAgent.indexOf("Firefox")!=-1){
        oType="FIREFOX";
    }
    return oType;
}